<template>
  <div class="pagemain">
    <div class="bgimg">
      <div class="pc_login">
        <div class="nwtabs">普通会员登录</div>
        <ul class="form_list">
          <li>
            <input
              v-model="uname"
              @blur="check_uname"
              placeholder="用户名/手机/邮箱"
              class="ip1"
            />
            <span v-if="icon1 === 1" class="iconfont icon-duigou"></span>
            <span v-else-if="icon1 === 0" class="iconfont icon-cha"></span>
            <span v-else></span>
          </li>
          <li>
            <input
              v-model="upwd"
              @blur="check_upwd"
              placeholder="输入密码"
              type="password"
              class="ip2"
            />
            <span v-if="icon2 === 1" class="iconfont icon-duigou"></span>
            <span v-else-if="icon2 === 0" class="iconfont icon-cha"></span>
            <span v-else></span>
          </li>
          <li class="cb">
            <input type="checkbox" />
            <span>7天内自动登录</span>
            <a href="#">忘记密码?</a>
          </li>
          <li class="bt">
            <button @click="checkform">登录</button>
          </li>
          <li>
            <router-link to="/register">没有账号？立即注册</router-link>
          </li>
        </ul>
        <p class="ts">
          温馨提示：
          <br />
          成功注册会员，登录后首次完善个人信息，即可获赠官网会员20积分
        </p>
      </div>
    </div>
  </div>
</template>


<script>
export default {
     data(){
       return {
         uname:'',
         upwd:'',
         icon1:'',
         icon2:''
       }
     },
     methods:{
        check_uname(){
          let uname=this.uname
          let reg=/^[\u4e00-\u9fa5a-zA-Z0-9]{6,12}$/
          if(reg.test(uname)){
            this.icon1=1
            return true
          }else{
            this.icon1=0 
            return false
          }
        },
        check_upwd(){
       let upwd=this.upwd
          let reg=/^\w{6,12}$/
          if(reg.test(upwd)){
            this.icon2=1
            return true
          }else{
            this.icon2=0 
            return false
          }
        },
        checkform(){
      if(this.check_uname && this.check_upwd){
        let url='/users/login';
        let param=`uname=${this.uname}&&upwd=${this.upwd}`;
        this.axios.post(url,param).then(
          (result)=>{
            console.log(result)
            if(result.data.code==200){
              alert('登陆成功!')
              
              //调用mutations更新登录状态
              let user=result.data.result
              this.$store.commit('updateLoginState',user)
              //把用户信息存入sessionstorage,刷新页面时使用
              sessionStorage.setItem('isLogin',1)
              sessionStorage.setItem('user',JSON.stringify(user))
              
              this.$router.push('/')
            }else{
              alert('输入的用户名或密码错误！请重新输入!')
              this.upwd=''
              this.uname=''
              this.icon1=''
              this.icon2=''
            }
          }
        )
      }
    }

}
}
</script>





<style scoped>
.pagemain {
  /* position: fixed; */
  margin-top: 95px;
  height: 475px;
  width: 100%;
  box-sizing: border-box;
  background-color: #e4004f;
}
.bgimg {
  width: 1100px;
  height: 400px;
  position: relative;
  margin: 0 auto;
  background: url(../assets/main.png) no-repeat 0 50px; 
}
.pc_login {
  width: 340px;
  height: 330px;
  background: #fff;
  box-sizing: border-box;
  position: absolute;
  right: 10px;
  top: 40px;
  padding: 30px;
}
.nwtabs {
  width: 280px;
  height: 35px;
  color: #555;
  font-size: 14px;
  font-weight: bold;
}
.form_list {
  font-size: 14px;
}
.form_list li {
  width: 100%;
  height: 40px;
}
/* .form_list .cb{
    height: 30px;
} */
.form_list .ip1 {
  width: 90%;
  border: 1px solid #dedede;
  padding: 8px;
  margin-right: 10px;
  box-sizing: border-box;
  outline: none;
  height: 30px;
}
.form_list .ip2 {
  width: 90%;
  border: 1px solid #dedede;
  padding: 8px;
  margin-right: 10px;
  box-sizing: border-box;
  outline: none;
  height: 30px;
}
.form_list a {
  color: #757575;
}
.cb {
  height: 25px !important;
}
.bt {
  height: 30px !important;
}

.cb a {
  float: right;
}
.form_list button {
  border: 1px solid #dedede;
  background-color: #e4004f;
  color: #fff;
  width: 280px;
  height: 30px;
  outline: none;
  line-break: 25px;
}
.ts {
  margin-top: 10px;
}
</style>